home *** CD-ROM | disk | FTP | other *** search
Wrap
`timescale 1 ns / 100 ps /* Linear Feedback Shift Register * verilog module "«font style◊bold»«field◊module»«font style◊plain»" * Generated by Macintosh application 'LFSR' «date» «time» «if not empty◊company◊ * company: «field ◊company»» «if not empty◊project◊ * project: «field ◊project»» «if not empty◊designer◊ * designer: «field ◊designer»» * prototypes: «font style◊bold»«field◊module»«font style◊plain»(«field◊clock»«if true◊«button◊ce enable»◊, «field◊clock enable»», «field◊preset»«if true◊«button◊sr enable»◊, «field◊shift register output»»«if true◊«button◊tc enable»◊, «field◊terminal count»»); «font style◊bold»«field◊module»«font style◊plain»(.«field◊clock»(CLOCK)«if true◊«button◊ce enable»◊, .«field◊clock enable»(CE)», .«field◊preset»(PRESET)«if true◊«button◊sr enable»◊, .«field◊shift register output»(Q)»«if true◊«button◊tc enable»◊, .«field◊terminal count»(TC)»); * * The counter reaches terminal count after «field◊count» « if true◊«button◊clock edge polarity»◊negative edge◊else◊positive edge» clocks. «if true◊«button◊tc enable»◊ * '«field ◊terminal count»' is asserted «if true◊«button◊tc polarity»◊high◊else◊low» at the end of count.» * count is preset synchronously by an active «if true◊«button◊preset polarity»◊high◊else◊low» on '«field◊preset»'.«if true◊«button◊retriggerable»◊ * The counter is free running. It presets itself on every terminal count.◊else◊ * The counter stops after terminal count and must be preset to count again.» «if true◊«button◊ce enable»◊ * The counting is suspended when '«field◊clock enable»' is asserted «if true◊«button◊ce polarity»◊high◊else◊low».»«if true◊«button◊sr enable»◊ * The shift register output of the counter is brought out of the module as '«field◊shift register output»'.»«if true◊«button◊combinatorial»◊ * The counter uses AND (or NAND) gates on the output of the shift register to detect for terminal count of all 'ones'.◊else◊ * The counter uses small auxiliary counter to detect for terminal count by counting all 'ones' being * shifted into the main counter. The preset of the small auxiliary counter is connected to the * input of the main shift register and terminal count is generated only when «get◊stages» '1' bits have shifted into the main counter. * The auxiliary counter is «get◊auxiliary stages» registers with two taps feedback to the input.» * The main counter consist of «get◊stages» registers with «get◊tap count» taps feedback to the input. */«set◊auxQ◊AUX_«field◊shift register output»» module «font style◊bold»«field◊module»«font style◊plain» («field◊clock»«if true◊«button◊ce enable»◊, «field◊clock enable»», «field◊preset»«if true◊«button◊sr enable»◊, «field◊shift register output»»«if true◊«button◊tc enable»◊, «field◊terminal count»»); input «field◊clock»; «if true◊«button◊ce enable»◊ input «field◊clock enable»;» input «field◊preset»; «if true◊«button◊tc enable»◊ output «field◊terminal count»;» «set◊max◊«-◊«get◊stages»◊1»»«set◊aux max◊«-◊«get◊auxiliary stages»◊1»»«if true◊«button◊sr enable»◊ output «field◊shift register output»;» reg [«get◊max»:0] D; reg [«get◊max»:0] «field◊shift register output»;«if true◊«button◊one shot»◊ wire isCounting;»«if true◊«button◊auxiliary counter»◊ reg [«get◊aux max»:0] AUX_D; reg [«get◊aux max»:0] «get◊auxQ»;» assign «field◊terminal count» = «if false◊«button◊tc polarity»◊~»&«if true◊«button◊auxiliary counter»◊«get◊auxQ»◊else◊«field◊shift register output»»; «if true◊«button◊one shot»◊ assign isCounting = «if false◊«button◊preset polarity»◊~»«field◊preset» | (isCounting & «if true◊«button◊tc polarity»◊~»«field◊terminal count»);» always @(«field◊shift register output» or «field◊preset»«if true◊«button◊retriggerable»◊ or «field◊terminal count»»«if true◊«button◊ce enable»◊ or «field◊clock enable»») begin casex ({«field◊preset»«if true◊«button◊retriggerable»◊, «field◊terminal count»»«if true◊«button◊ce enable»◊, «field◊clock enable»»}) // synopsys parallel_case full_case«if true◊«button◊ce enable»◊ 'b?«if true◊«button◊retriggerable»◊?»«if true◊«button◊ce enable»◊«button◊ce polarity»»: begin D = «field◊shift register output»; // suspend counting end» 'b«button◊preset polarity»«if true◊«button◊retriggerable»◊?»«if true◊«button◊ce enable»◊«not◊«button◊ce polarity»»»«if true◊«button◊retriggerable»◊, // preset to value 'b?«button◊tc polarity»«if true◊«button◊ce enable»◊«not◊«button◊ce polarity»»»»: // retrigger presets from TC begin D = 'h«as hex◊«get◊preset value»»; // preset to seed end 'b«not◊«button◊preset polarity»»«if true◊«button◊retriggerable»◊«not◊«button◊tc polarity»»»«if true◊«button◊ce enable»◊«not◊«button◊ce polarity»»»: // normal counting begin D[«get◊max»:1] = «field◊shift register output»[«-◊«get◊max»◊1»:0]; D[0] = «if true◊«button◊one shot»◊(»«field◊shift register output»[«-◊«get◊tap0»◊1»] ^ «field◊shift register output»[«-◊«get◊tap1»◊1»]«if true◊«>◊«get◊tap count»◊2»◊ ^ «field◊shift register output»[«-◊«get◊tap2»◊1»] ^ «field◊shift register output»[«-◊«get◊tap3»◊1»]»«if true◊«button◊one shot»◊) & isCounting»; end endcase end // always«if true◊«button◊auxiliary counter»◊ // Auxiliary counter for detecting terminal count // counts «get◊stages» bits of consecutive '1's always @(D[0] or «field◊preset»«if true◊«button◊retriggerable»◊ or «field◊terminal count»»«if true◊«button◊ce enable»◊ or «field◊clock enable»») begin casex ({D[0], «field◊preset»«if true◊«button◊retriggerable»◊, «field◊terminal count»»«if true◊«button◊ce enable»◊, «field◊clock enable»»}) // synopsys parallel_case full_case«if true◊«button◊ce enable»◊ 'b??«if true◊«button◊retriggerable»◊?»«if true◊«button◊ce enable»◊«button◊ce polarity»»: begin AUX_D = «get◊auxQ»; // suspend counting end» 'b0?«if true◊«button◊retriggerable»◊?»«if true◊«button◊ce enable»◊«not◊«button◊ce polarity»»», // preset counter if zero detected 'b?«button◊preset polarity»«if true◊«button◊retriggerable»◊?»«if true◊«button◊ce enable»◊«not◊«button◊ce polarity»»»«if true◊«button◊retriggerable»◊, // preset to value 'b??«button◊tc polarity»«if true◊«button◊ce enable»◊«not◊«button◊ce polarity»»»»: // retrigger presets from TC begin AUX_D = 'h«as hex◊«get◊auxiliary preset value»»; end 'b1«not◊«button◊preset polarity»»«if true◊«button◊retriggerable»◊«not◊«button◊tc polarity»»»«if true◊«button◊ce enable»◊«not◊«button◊ce polarity»»»: // normal counting begin AUX_D[«get◊aux max»:1] = «get◊auxQ»[«-◊«get◊aux max»◊1»:0]; AUX_D[0] = «if true◊«button◊one shot»◊(»«get◊auxQ»[«-◊«get◊auxiliary tap0»◊1»] ^ «get◊auxQ»[«-◊«get◊auxiliary tap1»◊1»]«if true◊«button◊one shot»◊) & isCounting»; end endcase end // always» // Shift register description always @(«if true◊«button◊clock edge polarity»◊negedge◊else◊posedge» «field◊clock») begin «field◊shift register output» = D; // make into D register«if true◊«button◊auxiliary counter»◊ «get◊auxQ» = AUX_D; // make into D register» end endmodule // «font style◊bold»«field◊module»«font style◊plain» «if true◊«button◊generate test module»◊ // synopsys translate_off module LFSR_Test_Counter(clock, ce, preset, tc); input clock; input ce; input preset; output tc; reg [31:0] count; assign tc = ~(count == 0); always @(«if true◊«button◊clock edge polarity»◊negedge◊else◊posedge» clock) begin if(preset == «button◊preset polarity»«if true◊«button◊retriggerable»◊ || count == 0») begin count = «-◊«field◊count»◊1»; end else if(«if true◊«button◊ce polarity»◊!»ce && count >= 0) begin count = count - 1; end end endmodule // LFSR_Test_Counter /* The Test module compares the LFSR counter with a conventional decrement counter * any discrepancy between the two counters will be displayed * The number of clocks to terminal count is always displayed */ module Test_«field◊module»; reg clock; reg enable; reg ce;«if true◊«button◊sr enable»◊ reg [«get◊max»:0] Q;» integer i; «font style◊bold»«field◊module»«font style◊plain» T0(clock«if true◊«button◊ce enable»◊, ce», enable«if true◊«button◊sr enable»◊, Q»«if true◊«button◊tc enable»◊, tc»); LFSR_Test_Counter T1(clock, ce, enable, tc2); initial begin i = 0; clock = 0; ce = «not◊«button◊ce polarity»»; enable = «button◊preset polarity»; #«*◊«get◊clock units»◊2» enable = «not◊«button◊preset polarity»»; «if true◊«button◊ce enable»◊ #«*◊«get◊clock units»◊4» ce = «button◊ce polarity»; #«*◊«get◊clock units»◊4» ce = «not◊«button◊ce polarity»»;» #«*◊«get◊maximum count»◊«*◊«get◊clock units»◊4»» $finish; end always begin #«get◊clock units» clock = ~clock; end always @(posedge clock) begin«if true◊«button◊tc enable»◊ if(tc == «button◊tc polarity») begin $display("Terminal count occurs at clock #%d", i); end if(tc != tc2) begin $display("Discrepancy between LFSR counter and test counter at clock #%d", i); $display("LFSR terminal count %b, Test terminal count %b",tc, tc2); end //» $display("%d - ce %b, preset %b«if true◊«button◊tc enable»◊ ,tc %b», test tc %b«if true◊«button◊sr enable»◊, Q %x»", i, ce, enable«if true◊«button◊tc enable»◊, tc», tc2«if true◊«button◊sr enable»◊, Q»); if(ce) i = i + 1; end endModule // Test_«field◊module» // synopsys translate_on »